<div id="site-nav" data-spm="a2226mz">
  <div id="sn-bg">
    <div class="sn-bg-right"></div>
  </div>
  <style type="text/css">
    .location-wrap {display: inline-block;margin-left: 18px;}
    .location-wrap .currentLocation {display: inline-block;}
    .location-wrap .selectArea {position:relative;display: inline-block;height: 32px;line-height: 32px;margin-left: 10px;color: #3C3C3C;}
    .location-wrap .selectArea:hover {background-color: #fff;}
    .location-wrap .selectArea:hover .arealist {display: block;}
    /*.location-wrap .selectArea:hover .currentcity:after {transform: rotate(45deg);}*/
    .location-wrap .currentcity {position: relative;height: 100%;padding: 0 25px 0 5px;}
    .location-wrap .currentcity:after {content: '';position: absolute;top: 0;bottom: 3px;right: 10px;margin: auto;width: 5px;height: 5px;border-top: 1px solid #9c9c9c;border-left: 1px solid #9c9c9c;transform: rotate(-135deg);transition: all .3s;}
    .location-wrap .arealist {display: none;overflow: auto;overscroll-behavior: contain;position: absolute;left: -1px;max-height: 280px;width: 220px;padding: 8px 0;background-color: #fff;border: 1px solid #EEE;}
    .location-wrap .areaitem {padding-left: 8px;cursor: pointer;}
    .location-wrap .areaitem:hover {background-color: #F5F5F5;}
    .location-wrap .relocation {margin-left: 5px; text-decoration: underline;cursor: pointer;padding-bottom: 3px;color: #666;}
  </style>
  <div id="sn-bd">
    <b class="sn-edge"></b>
    <div class="sn-container">
      <p id="login-info" class="sn-login-info">{{if .mem}}<a href="/my"><img src="{{.mem.pathname}}">&nbsp;&nbsp;{{.mem.monicker}}</a>&nbsp;&nbsp;<a style="color:#E31939" href="/logout">退出</a>{{else}}<a style="color:#E31939" href="/login">请登入</a>&nbsp;&nbsp;<a style="color:#E31939" href="/login_wechat">微信扫码登入</a>&nbsp;&nbsp;<a href="/sign">注册</a></p>{{end}}
      <div class="location-wrap">
        <p id="currentLocation" class="currentLocation">{{if .currentcity}}当前位置: {{ .currentcity }}{{else}}定位中{{end}}</p>
        <div class="selectArea">
          <p class="currentcity">{{.cityshop.currentcity.area}}</p>  
          <ul class="arealist" id="arealist">
            {{range .cityshop.citylist}}
            <li class="areaitem" data-id="{{.id}}">{{.area}}</li>
            {{end}}
          </ul>
        </div>
      </div>
      <ul class="sn-quick-menu">
        <li class="sn-cart">
          <div class="sn-menu">
            <a class="sn-cart-link" href="/">首页
            </a>
          </div>
        </li>
        <li class="sn-mytaobao menu-item j_MyTaobao">
          <div class="sn-menu">
            <a class="menu-hd" href="/my">我的统采
              <b></b>
            </a>
            <div class="menu-bd">
              <div class="menu-bd-panel" id="myTaobaoPanel">
                <a href="/my/order">已买到的宝贝</a>
                <a href="/my/foot">我的足迹</a>
              </div>
            </div>
          </div>
        </li>
        <li class="sn-seller-center hidden j_SellerCenter">
          <a target="_top" href="#">商家中心</a></li>
        <li class="sn-cart">
          <i class="mui-global-iconfont iconfont">&#xe70a;</i>
          <a class="sn-cart-link" href="/shopcar">购物车</a></li>
        <li class="sn-favorite menu-item">
          <div class="sn-menu">
            <a class="menu-hd" href="/my/collect">收藏夹
              <b></b>
            </a>
            <div class="menu-bd">
              <div class="menu-bd-panel">
                <a href="/my/collect">收藏的宝贝</a>
                <a href="/my/focus">收藏的店铺</a></div>
            </div>
          </div>
        </li>
        <li class="sn-separator"></li>
        <li class="sn-mobile">
          <i class="mui-global-iconfont iconfont">&#xe616;</i>
          <a title="统采无线" target="_top" class="sn-mobile-link" href="#">手机版</a></li>
        <li class="sn-home">
          <a href="/">统采网</a></li>
        <!-- <li class="sn-seller menu-item">
          <div class="sn-menu J_DirectPromo">
            <a class="menu-hd" href="#">商家支持
              <b></b>
            </a>
            <div class="menu-bd sn-seller-lazy"></div>
          </div>
        </li> -->
        <style type="text/css">
          .menu-bd-panel a{position: relative;}
          .menu-bd-panel a input{position: absolute;left: 0;top: 0;opacity: 0}
        </style>
        {{if .mem}}
        <li class="sn-mytaobao menu-item j_MyTaobao">
          <div class="sn-menu">
            <a class="menu-hd">采购模板
              <b></b>
            </a>
            <div class="menu-bd">
              <div class="menu-bd-panel" id="myTaobaoPanel">
                <a href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/excelmodel.rar">采购模板下载</a>
                <a><input type="file" accept=".xlsx" onchange='xlsxUpload(this)'>采购模板导入</a>
              </div>
            </div>
          </div>
        </li>
        {{end}}
      </ul>
    </div>
  </div>
</div>
<!-- <script src="https://api.map.baidu.com/api?v=3.0&ak=reS8936U13ZRG55lwohgtuubGqwNvsqh&s=1" type="text/javascript"></script> -->
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/pc/js/jquery.min.js"></script>
<script type="text/javascript">
    
  {{if .currentcity}}
  {{else}}
  tnLocation()
  // _location()
  {{end}}
  function tnLocation() {   //腾讯定位
    $.getScript('https://apis.map.qq.com/ws/location/v1/ip?callback=showLocation&key=U3HBZ-5JOKQ-JK454-GIYO5-HAZFQ-JQBZQ&output=jsonp')
  }
  function showLocation(data) {
    var city = data.result.ad_info.city
    relocation(city)
  }
  document.getElementById("arealist").onclick = function (e) {
    var el = e.target
    if (el.localName == "li") {
      var id = el.getAttribute("data-id")
      $.ajax({
        url: '/changeShop',
        data: {shopid: id},
        success: function (res) {
          if (res.status == 1) {
            location = location.origin
          }
        }
      })
    }
  }
  
  function _location() {
    var city = ''
    var geolocation = new BMap.Geolocation() 
    geolocation.enableSDKLocation();
    geolocation.getCurrentPosition(function(r){  
        if(this.getStatus() == BMAP_STATUS_SUCCESS){  
            var pt = new BMap.Point(r.point.lng,r.point.lat)  
            var geoc = new BMap.Geocoder()
            geoc.getLocation(pt, function(rs){
                var addComp = rs.addressComponents
                city = addComp.city
                console.log(city)
                relocation(city)
            });      
        }  
        else {  
          var myCity = new BMap.LocalCity()
          myCity.get(Ipmap)        
        }          
    },{enableHighAccuracy: true})
  }
  function Ipmap(res) {
    city = res.name
    console.log(city)
    relocation(city)
  }
  function relocation(city) {
    if (!city) {
      showToast("定位失败")
      document.getElementById("currentLocation").innerHTML = '定位失败<span id="relocation" class="relocation">重新定位</span>'
      document.getElementById("relocation").onclick = tnLocation
      return
    }
    $.ajax({
      url: '/relocation',
      data: {
        city: city
      },
      success: function (res) {
        if (res.status == 1) {
          location = location.origin
        } else if (res.status == 0) {
          document.getElementById("currentLocation").innerText = '当前位置: ' + city
          if (document.getElementById("relocation")) {
            document.getElementById("relocation").onclick = null
          }
        } else {
          showToast("定位失败")
          document.getElementById("currentLocation").innerHTML = '定位失败<span id="relocation" class="relocation">重新定位</span>'
          document.getElementById("relocation").onclick = tnLocation
        }
      }
    })
  }
  function xlsxUpload(e){
    var that=$(e);
    var file=e.files[0];
    var form = new FormData();
    form.append("file",file)
    $.ajax({
      url:"/excel/upload",
      data:form,
      type: "post",
      dataType: "json",
      cache: false,//上传文件无需缓存
      processData: false,//用于对data参数进行序列化处理 这里必须false
      contentType: false, //必须
      success:function(res){
        console.log(res)
        if (res.status==0) {
          window.wxc.xcConfirm("导入失败,请检查文件","error")
        }else{
          window.wxc.xcConfirm(res.msg,"success")
        }
      }
    })
  } 
</script>